import 'package:apple_style_wechat/contact/contacts_page.dart';
import 'package:apple_style_wechat/discover/discover_page.dart';
import 'package:apple_style_wechat/me/me_page.dart';
import 'package:apple_style_wechat/wechat/wechat_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'constants.dart';

class AppleStyleWechat extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '微信',
      home: HomePage(),
      debugShowCheckedModeBanner: false,
      theme: Theme.of(context).copyWith(
        primaryColor: Color(AppColors.AppBarColor),
        cardColor: Color(AppColors.AppBarColor),
        splashColor: Color(0x80000000),
      ),
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    BottomNavigationBarItem _buildBarItem(
        int iconName, int activeIconName, String title) {
      return BottomNavigationBarItem(
        icon: Icon(
          IconData(iconName, fontFamily: Constants.IconFontFamily),
          size: 25.0,
        ),
        activeIcon: Icon(
          IconData(activeIconName, fontFamily: Constants.IconFontFamily),
          size: 25.0,
        ),
        title: Text(title),
      );
    }

    return CupertinoTabScaffold(
      backgroundColor: CupertinoColors.white,
      tabBar: CupertinoTabBar(
        backgroundColor: Color(0xffF7F7F7),
        iconSize: 25.0,
        activeColor: Color(AppColors.TabIconActiveColor),
        inactiveColor: Color(AppColors.TabIconNormalColor),
        border: Border(
          top: BorderSide(color: Colors.grey[200]),
        ),
        items: <BottomNavigationBarItem>[
          _buildBarItem(0xe600, 0xe61b, '微信'),
          _buildBarItem(0xe601, 0xe602, '通讯录'),
          _buildBarItem(0xe629, 0xe62a, '发现'),
          _buildBarItem(0xe63a, 0xe63e, '我'),
        ],
      ),
      tabBuilder: (BuildContext context, int index) {
        assert(index >= 0 && index <= 3);
        switch (index) {
          case 0:
            return CupertinoTabView(
              builder: (BuildContext context) => WechatPage(),
            );
            break;
          case 1:
            return CupertinoTabView(
              builder: (BuildContext context) => ContactsPage(),
            );
            break;
          case 2:
            return CupertinoTabView(
              builder: (BuildContext context) => DiscoverPage(),
            );
            break;
          case 3:
            return CupertinoTabView(
              defaultTitle: '我',
              builder: (BuildContext context) => MePage(),
            );
            break;
          default:
        }
      },
    );
  }
}
